﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace BioBooking.WebClient.UserControls
{
    public partial class ShowMovieThumbnails : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BioBooking.Data.BioBookingContainer container = new Data.BioBookingContainer();
                var movies = container.MovieSet.Where(p=>p.isActive).Where(p=>p.Showings.Any());

                var activeMovies = from p in container.MovieSet
                                   where p.isActive
                                   where p.Showings.Any()
                                   where p.ScreenShot.Any()
                                   select new {
                                       thumbnailID = p.ScreenShot.FirstOrDefault().Id,
                                       p.Id,
                                       p.Titel,
                                       nextShowing = p.Showings.OrderBy(x=>x.Date).FirstOrDefault()
                                   };

                lvThumbnails.DataSource = activeMovies.Take(3);
                lvThumbnails.DataBind();
            }
        }
    }
}